package com.bootx.officialAccount.service.impl;

import com.bootx.officialAccount.dao.MaterialDao;
import com.bootx.officialAccount.dao.NewsItemDao;
import com.bootx.officialAccount.entity.Material;
import com.bootx.officialAccount.entity.NewsItem;
import com.bootx.officialAccount.entity.OfficialAccount;
import com.bootx.officialAccount.service.MaterialService;
import com.bootx.officialAccount.service.NewsItemService;
import com.bootx.officialAccount.service.OfficialAccountService;
import com.bootx.service.impl.BaseServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author black
 */
@Service
public class MaterialServiceImpl extends BaseServiceImpl<Material,Long> implements MaterialService {

    @Resource
    private MaterialDao materialDao;

    @Resource
    private NewsItemService newsItemService;


    @Override
    public void create(Material material) {
        List<NewsItem> content = material.getContent();
        Material material1 = materialDao.find("mediaId", material.getMediaId());
        if(material1==null){
            material1 = super.save(material);
            Material finalMaterial = material1;
            content.forEach(item->{
                item.setMaterial(finalMaterial);
                newsItemService.save(item);
            });
        }
    }
}
